import React from 'react';
import { connect } from 'react-redux';
import { message } from 'antd';
import Api from 'Utils/api';
import { GetLevel } from 'Constants/emergenceLevel';
import CommonBg from 'Page/DispatchPage/Components/CommonBorder';

class CustomPlanDetail extends React.PureComponent {
  constructor(props) {
    super(props);
    this.state = {
      id: props.params.id,
      data: {},
    };
    this.initList = ::this.initList;
  }
  componentDidMount() {
    this.initList();
  }
  initList() {
    const { id } = this.state;
    const api = new Api({
      method: 'GET',
      path: `/schemas/${id}`,
      success: (json) => {
        this.setState({ data: json });
      },
      error: (msg) => {
        message.error(msg);
      }
    });
    api.run();
  }
  render() {
    const { data } = this.state;
    const levelName = data.event_level ? GetLevel(data.event_level) : {};
    return (
      <CommonBg
        title="自定义预案"
        content={
          <div className="advice-detail-page">
            <div className="advice-detail-content">
              <div className="item">
                <span>预案标题：</span>
                <span>{data.title}</span>
              </div>
              <div className="item">
                <span>事件等级：</span>
                <span>{levelName.name || ''}</span>
              </div>
              <div className="item">
                <span>业务流程：</span>
                <span>{data.operation_flow}</span>
              </div>
            </div>
          </div>
        }
      />
    );
  }
}
function mapStateToProps(state) {
  return {
    ...state.routing,
  };
}

export default connect(mapStateToProps)(CustomPlanDetail);
